package com.alix.paymoney.presenter.impl;

import com.alix.paymoney.entity.DataBean;
import com.alix.paymoney.http.CallManager;
import com.alix.paymoney.http.HttpManager;
import com.alix.paymoney.http.OnResponseListener;
import com.alix.paymoney.http.request.LoginRequest;
import com.alix.paymoney.presenter.LoginPresenter;
import com.alix.paymoney.utils.Loger;
import com.alix.paymoney.view.LoginView;

import retrofit2.Call;

/**
 * Created by wushiqian on 2017/11/13.
 */

public class LoginPresenterImpl extends BasePresenterImpl<LoginView> implements LoginPresenter {
    public LoginPresenterImpl(LoginView loginView) {
        super(loginView);
    }

    @Override
    public void login(String telephone, String code) {
        LoginRequest request = new LoginRequest();
        request.setTelphone(telephone);
        request.setVerifyCode(code);
        Call<DataBean> login = HttpManager.getInstance().getApiService().login(telephone,code);
        CallManager.getInstance().addQueue(login, new OnResponseListener<DataBean>() {
            @Override
            public void Success(DataBean o) {
                getView().LoginSuccess(o.getData());
            }

            @Override
            public void onFailed(int errorCode, String errorInfo) {
                getView().loginError(errorCode, errorInfo);
                Loger.e(errorCode + "登录" + errorInfo);
            }

            @Override
            public void onException(String msg) {
                getView().showTips(msg);
            }
        });
    }
}
